import { PrimaryTableCol, Space, TableRowData, Tag } from 'tdesign-vue-next';

import { ActionBarItem } from '@/components/common-action-bar/index.vue';
import { t } from '@/locales';
import { tableActionBtn } from '@/utils/action';

import { SearchBarItem } from '../../../components/common-search-bar/index.vue';

export const SEARCH_BAR_DATA: SearchBarItem[] = [
  { label: 'pages.log.manage', component: 'select', name: 'username', width: 280, labelWidth: 100 },
  { label: 'pages.log.daterange', component: 'daterange', name: 'createdAt', value: [], width: 360, labelWidth: 100 },
];

export const ACTION_BAR_DATA: ActionBarItem[] = [
  {
    text: 'common.delete',
    theme: 'danger',
    disabled: true,
    auth: ['system:operation-log:batchDel'],
    key: 'listBatDel',
    message: t('common.deleteSelectConfirm'),
  },
  {
    text: 'pages.log.clear',
    theme: 'danger',
    auth: ['system:operation-log:clear'],
    key: 'listClear',
    message: t('common.clearConfirm'),
  },
];

export const COLUMNS: PrimaryTableCol<TableRowData>[] = [
  { colKey: 'row-select', type: 'multiple', width: 46 },
  { title: 'ID', colKey: 'id', width: 100 },
  { title: () => t('pages.log.manage'), colKey: 'username' },
  { title: () => t('pages.log.module'), colKey: 'module' },
  { title: () => t('common.operation'), colKey: 'operation' },
  {
    title: () => t('common.status'),
    colKey: 'status',
    cell(h, { row: { status } }) {
      return h(Tag, {
        variant: 'light',
        shape: 'round',
        theme: ['danger', 'success'][status] as 'danger' | 'success',
        content: ['失败', '成功'][status],
      });
    },
  },
  { title: 'ip', colKey: 'ip' },
  { title: () => t('pages.log.city'), colKey: 'address' },
  { title: () => t('pages.log.system'), colKey: 'os' },
  { title: () => t('pages.log.browser'), colKey: 'browser' },
  { title: () => t('pages.log.times'), colKey: 'taketime' },
  { title: () => t('common.createAt'), colKey: 'createdAt', width: 180 },
  {
    title: () => t('common.operation'),
    colKey: 'action',
    width: 100,
    cell(h, { row }) {
      const actionDelete = tableActionBtn({ h, type: 'delete', row, auths: ['system:login-log:delete'] });
      return h(Space, () => {
        return [actionDelete];
      });
    },
  },
];
